# @Author   : 懒羊羊
# @File     : search.py
# @Time     : 2024/12/11 19:49
import time

from appium import webdriver
from appium.options.common import AppiumOptions
from appium.webdriver.common.appiumby import AppiumBy
from selenium.webdriver.support.wait import WebDriverWait

url = "http://127.0.0.1:4723/wd/hub"

options = AppiumOptions()

options.set_capability('platformName', 'Android')
options.set_capability('platformVersion', '9')
options.set_capability('deviceName', 'xxx')
# options.set_capability('appPackage', 'com.kkpodcast')
# options.set_capability('appActivity', 'com.kkpodcast.activity.WelcomeActivity')
options.set_capability('noReset', True)
options.set_capability('browserName', 'Browser')
options.set_capability('chromedriverExecutable',
                       r'D:\python-workspace\python-lizhe\python-base-trl\appAuto\chromedriver.exe')

# 初始化 driver
driver = webdriver.Remote(url, options=options)
# 打开网页
driver.get("https://www.baidu.com/")
print(driver.contexts)

l = driver.contexts
# 切换到 CHROMIUM 上下文
# driver.switch_to.context(l[-1])
# 点击输入框
# driver.find_element(AppiumBy.CSS_SELECTOR, '.input-wrapper').click()
# WebDriverWait(driver, 10, 0.5).until(
    # lambda driver: driver.find_element(AppiumBy.CSS_SELECTOR, '.input-wrapper')).click()
# Base().getElement(driver, AppiumBy.CSS_SELECTOR, '.input-wrapper').click()
# time.sleep(2)
# 输入内容
# driver.find_element(AppiumBy.CSS_SELECTOR, 'input[type="search"]').send_keys('蜡笔小新')
WebDriverWait(driver, 10, 0.5).until(
    lambda driver: driver.find_element(AppiumBy.CSS_SELECTOR, 'input[type="search"]')).send_keys('蜡笔小新')
# time.sleep(2)
# 点击百度一下
# driver.find_element(AppiumBy.CSS_SELECTOR, '#index-bn').click()
WebDriverWait(driver, 10, 0.5).until(
    lambda driver: driver.find_element(AppiumBy.CSS_SELECTOR, '#index-bn')).click()
time.sleep(5)
